#!/bin/bash
# Autor: Ricardo Brito do Nascimento
# email: r
# data: 20080118

HOST=localhost
PORT=5432
USER=postgres
DIR=/srv/backups
EXT=.backup
DB=(postgres horde dialogo SAPNPM SecomWeb coi)

_pgdump(){
    x=0
    while [ $x != ${#DB[@]} ]; do
	pg_dump -ivbF c -h $HOST -p $PORT -U $USER -f $DIR/pg_${DB[$x]}$EXT ${DB[$x]}
	let "x++"
    done
}

#case $# in
#      0|4)
#	if [ $# == 0 ]; then
#		echo 0 parametros;
#		_pgdumpall $HOST $PORT $USER $DIR
#	fi
#	if [ $# == 4 ]; then
#        	echo 4 parametros;
#        	_pgdumpall $1 $2 $3 $4
#	fi ;;
#       
#      *) echo "O script deve ter 4 parametros: host, porta, usuario, diretorio destino" 
#        echo "OBS: a ordem deve ser repeitada";
#        echo
#	echo 'ex: '$0'  localhost 5432 postgres /tmp';;
#esac

echo ${DB[@]}
echo ${#DB[@]}
echo ${DB[1]}
echo ${DB[@]:2}
_pgdump
